import threading

from selenium import webdriver


class BrowserUtils(object):
    _instance_lock = threading.Lock()

    def __init__(self):
        self.browser = webdriver.Chrome()

    @classmethod
    def instance(cls, *args, **kwargs):
        with BrowserUtils._instance_lock:
            if not hasattr(BrowserUtils, "_instance"):
                BrowserUtils._instance = BrowserUtils(*args, **kwargs)
        return BrowserUtils._instance

    def load(self, url):
        self.browser.get(url)

    def set(self, id, value):
        self.browser.find_element_by_id(id).send_keys(value)

    def setByName(self, name, value):
        self.browser.find_element_by_name(name).send_keys(value)

